package com.qwc.blog.web.admin;

import com.qwc.blog.common.constant.ResponseConstant;
import com.qwc.blog.entity.dto.LoginDto;
import com.qwc.blog.service.ILoginService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @author qiuwencong
 * @Date 2022/1/24 11:01
 * @Package com.qwc.blog.web.admin.common
 * @Description
 */
@Slf4j
@RestController
@RequestMapping
public class LoginController {

    @Autowired
    private ILoginService loginService;

    @PostMapping("login")
    public ResponseEntity<Object> login(@Validated @RequestBody LoginDto dto){
        Map<String,Object> map = new HashMap<>(2);
        map.put(ResponseConstant.TOKEN,loginService.authenticate(dto));
        return ResponseEntity.ok(map);
    }
}
